package com.wens.baselibrary.example

import android.content.Context
import android.os.Bundle
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.wens.baselibrary.module.BaseModuleImpl
import com.wens.baselibrary.present.BasePresentImpl
import com.wens.baselibrary.service.DemoService
import com.wens.baselibrary.view.BaseView
import com.wens.baselibrary.view.activity.BaseActivity

class ExampleActivity : BaseActivity<ExamplePresent>(),
    BaseView {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_example)
    }

    @Autowired(name = "base/demo")
    internal val demoService: DemoService? = null


    override fun initData(context: Context) {
        present.doSomething()
    }

    override fun initView(context: Context) {

    }

    override fun createPresent(): ExamplePresent {
        return ExamplePresent(this)
    }

    fun afterDoSomething() {
        demoService?.startNewActivity()
    }


}

class ExamplePresent(view: ExampleActivity) : BasePresentImpl<ExampleActivity, ExampleModel>(view) {

    override fun createModel(): ExampleModel = ExampleModel(this)

    fun doSomething() {
        model.doSomething()
    }

    fun afterDoSomething() {
        view.afterDoSomething()
    }

}

class ExampleModel(present: ExamplePresent) : BaseModuleImpl<ExamplePresent>(present) {
    fun doSomething() {
        present.afterDoSomething()
    }

}
